APPKEY is the Application Key for a (free) http://www.realtime.co/ "Realtime Messaging Free" subscription.
See "104 - Remote deurbel - Een cloud API gebruiken om berichten te sturen" voor meer gedetailleerde info.
In [ ]:
APPKEY = "******"
First set up the necessary conections to drive a LED (see 102 - LEDs - Drive LEDS with the Raspberry Pi GPIO pins for an illustration; we'll be using PIN 18, but above all make sure you do not forget the resistor!)
In [ ]:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
PIN = 18
GPIO.setup(PIN, GPIO.OUT)
def flash_led():
GPIO.output(PIN, 1)
time.sleep(0.5)
GPIO.output(PIN, 0)
Create a function that defines what happens when a message comes in.
In [ ]:
def on_message(sender, channel, message):
print("Received a message via {}: {}".format(channel, message))
flash_led()
And eventually subscribe to the "doorbell" channel to read out messages
In [ ]:
import ortc
oc = ortc.OrtcClient()
oc.cluster_url = "http://ortc-developers.realtime.co/server/2.1"
def on_connected(sender):
print('Connected')
oc.subscribe('doorbell', True, on_message)
oc.set_on_connected_callback(on_connected)
oc.connect(APPKEY)
Et voilá, send a message with the send script or by means of the realtime.co console.
In [ ]:
GPIO.cleanup()